package com.example.comon.exception;


import com.example.comon.domain.R;
import jdk.nashorn.internal.runtime.logging.Logger;
import org.apache.logging.log4j.LogManager;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;

/**
 * 全系统异常捕获
 */
@RestControllerAdvice
@Logger
public class GlobalExceptionHandler {

    private static final org.apache.logging.log4j.Logger log = LogManager.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(RuntimeException.class)
    public R handleRuntimeException(RuntimeException e, HttpServletRequest request) {
        log.error(e);
        return R.error(e.getMessage());
    }
}
